package com.situ.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.pojo.Category;
import com.situ.mall.pojo.query.CategoryQuery;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> selectTopCategory() {
        return categoryMapper.selectTopCategory();
    }

    @Override
    public List<Category> selectSecondCategoryByTopCategoryId(Integer id) {
        return categoryMapper.selectSecondCategoryByTopCategoryId(id);
    }

    @Override
    public int selectTopCategoryIdByCategoryId(Integer categoryId) {
        return categoryMapper.selectTopCategoryIdByCategoryId(categoryId);
    }
    @Override
    public PageResult<Category> list(CategoryQuery categoryQuery) {
        PageHelper.startPage(categoryQuery.getPage(),categoryQuery.getLimit());
        List<Category> list = categoryMapper.list(categoryQuery);
        PageInfo pageInfo = new PageInfo(list);
        int count = (int) pageInfo.getTotal();
        return new PageResult<>(0,"",count,list);
    }

    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteByPrimaryKey(id);
    }

    /*@Override
    public void deleteAll(int[] ids) {

    }*/

    @Override
    public void deleteAll(Integer[] ids) {
        categoryMapper.deleteAll(ids);
    }

    @Override
    public int selectTopCategoryByCategory(Integer categoryId) {
        return categoryMapper.selectTopCategoryByCategory(categoryId);
    }

    @Cacheable(value = "category",key = "#root.methodName")
    /*@Override
    public void add1(Category category) {
        categoryMapper.insertSelective(category);
    }*/

    @Override
    public List<Category> selectAll() {
        return categoryMapper.selectAll();
    }

    @Override
    public void add(Category category) {
        categoryMapper.insertSelective(category);

    }


}
